package logic

import (
	"context"
	"gorm.io/gorm"
	"netease/models/mysql"

	"netease/neteaserpc/internal/svc"
	"netease/neteaserpc/neteaserpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 更新
func (l *UpdateLogic) Update(in *neteaserpc.UpdateRequest) (*neteaserpc.UpdateResponse, error) {
	// todo: add your logic here and delete this line
	user := mysql.Netease{
		Model:    gorm.Model{ID: uint(in.Id)},
		Account:  in.Account,
		Password: in.Password,
		Content:  in.Content,
	}
	mysql.DB.Where("id=?", in.Id).Updates(&user)
	return &neteaserpc.UpdateResponse{
		Id: int64(user.ID),
	}, nil
}
